package com.pts_socuse.controller;

import com.pts_socuse.result.Result;
import com.pts_socuse.service.HurdlesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "栏圈管理模块")
@RestController
@RequestMapping("/hurdle")
public class HurdleController {

    @Autowired
    private HurdlesService hurdlesService;

    @GetMapping("/queryAllMax")
    @Operation(summary = "查询所有栏圈的容量")
    public Result queryAllMax(){
        return Result.success(hurdlesService.queryAllMax());
    }

    @GetMapping
    @Operation(summary = "查询所有栏圈带分页带条件，并且携带所属栏舍")
    @Parameters({
            @Parameter(name = "hName",description = "栏圈名称",in = ParameterIn.QUERY),
            @Parameter(name = "hMax",description = "栏圈容量",in = ParameterIn.QUERY),
            @Parameter(name = "fhName",description = "栏舍名称",in = ParameterIn.QUERY),
            @Parameter(name = "hEnable",description = "栏圈启用状态",in = ParameterIn.QUERY),
            @Parameter(name = "pageNum",required = true,description = "当前页码",in = ParameterIn.QUERY),
            @Parameter(name = "pageSize",required = true, description = "每页大小",in = ParameterIn.QUERY),
    })
    public Result getAllByConditionByPage(@RequestParam(required = false) String hName,
                                          @RequestParam(required = false) Integer hMax,
                                          @RequestParam(required = false) String fhName,
                                          @RequestParam(required = false) String hEnable,
                                          Integer pageNum,
                                          Integer pageSize){
        return Result.success(hurdlesService.getAllByConditionByPage(hName,hMax,fhName,hEnable,pageNum,pageSize));
    }

    @PutMapping("/{hId}/{hEnable}")
    @Operation(summary = "修改栏圈启用状态")
    public Result updateHurdleEnable(@PathVariable String hId,
                                     @PathVariable String hEnable){
        hurdlesService.updateHEnable(hId,hEnable);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "批量禁用/启用栏圈状态")
    public Result updateHurdleEnableBatch(@RequestBody List<Map<String,String>> list){
        return Result.success();
    }

    @GetMapping("/queryAllEnable")
    @Operation(summary = "查询所有可用的栏圈")
    public Result queryAllEnable(){
        return Result.success(hurdlesService.queryAllEnable());
    }

}